{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Managing variables\n",
    "### Preparation"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "%config IPCompleter.greedy = True\n",
    "%load_ext autoreload\n",
    "%autoreload 2\n",
    "\n",
    "import qiskit_metal as metal\n",
    "from qiskit_metal import designs, qlibrary, draw\n",
    "from qiskit_metal import MetalGUI, Dict"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "design = designs.DesignPlanar()\n",
    "gui = MetalGUI(design)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from qiskit_metal.qlibrary.qubits.transmon_pocket import TransmonPocket\n",
    "from qiskit_metal.qlibrary.tlines.meandered import RouteMeander\n",
    "\n",
    "connection_pads = dict(connection_pads=dict(\n",
    "                a = dict(loc_W=+1,loc_H=+1), \n",
    "                b = dict(loc_W=-1,loc_H=+1),\n",
    "                c = dict(loc_W=+1,loc_H=-1),\n",
    "                d = dict(loc_W=-1,loc_H=-1)\n",
    "            ))\n",
    "q1 = TransmonPocket(design, 'Q1', options = dict(pos_x='-1.5mm', pos_y='+0.0mm', **connection_pads))\n",
    "q2 = TransmonPocket(design, 'Q2', options = dict(pos_x='+1.5mm', pos_y='+0.0mm', **connection_pads))\n",
    "q3 = TransmonPocket(design, 'Q3', options = dict(pos_x='+0.0mm', pos_y='+1.3mm', **connection_pads))\n",
    "\n",
    "\n",
    "\n",
    "options = Dict(\n",
    "    pin_inputs=Dict(\n",
    "        start_pin=Dict(\n",
    "            component= 'Q1',\n",
    "            pin= 'a'),\n",
    "        end_pin=Dict(\n",
    "            component= 'Q2',\n",
    "            pin= 'b')),\n",
    ")\n",
    "design.variables.cpw_width = '10um'\n",
    "design.variables.cpw_gap = '6um'\n",
    "cpw = RouteMeander(design, 'cpw', options)\n",
    "\n",
    "gui.rebuild()\n",
    "gui.autoscale()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "design.parse_value(\"['10um', '1nm']\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "metal.config.DefaultMetalOptions.default_generic.units"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# outdated: gui.ui.tabWidget.setTabPosition(0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "table = gui.variables_window.ui.tableView\n",
    "table.resizeColumnsToContents()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from PySide2.QtWidgets import QAbstractItemView\n",
    "table.setVerticalScrollMode(QAbstractItemView.ScrollPerPixel)\n",
    "table.setHorizontalScrollMode(QAbstractItemView.ScrollPerPixel)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "table.adjustSize()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gui.config.clear()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "gui.screenshot()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set variables in the design\n",
    "design.variables.pad_width = '400 um'\n",
    "\n",
    "# Assign variables to component options\n",
    "q1.options.pad_width = 'pad_width'\n",
    "q2.options.pad_width = 'pad_width'\n",
    "q3.options.pad_width = 'pad_width'\n",
    "\n",
    "# Rebuild all compoinent and refresh the gui \n",
    "gui.rebuild()\n",
    "gui.autoscale()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set variables in the design\n",
    "design.variables.pad_width = '300 um'\n",
    "\n",
    "# Rebuild all compoinent and refresh the gui \n",
    "gui.rebuild()\n",
    "gui.autoscale()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Set variables in the design\n",
    "design.variables.pad_width = '550 um'\n",
    "\n",
    "# Rebuild all compoinent and refresh the gui \n",
    "gui.rebuild()\n",
    "gui.autoscale()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "q1.qgeometry_bounds()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# outdated: q1.qgeometry_list()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "q1.qgeometry_plot"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "type(q1.qgeometry_table('poly'))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "q1.qgeometry_table('poly')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# outdated: gui.component_window.model.index(1,0)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
